import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';

class YBWorkTaiGongGaoSubPage extends StatelessWidget {

  final String title;
  final String subTitle;
  final String idstr;
  final String createTime;
  const YBWorkTaiGongGaoSubPage({Key key, this.title, this.subTitle,this.idstr,this.createTime}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    Widget createWidget;
    if (createTime != null){
       DateTime dateTime = DateUtil.getDateTime(createTime);
       DateTime nowTime = DateTime.now();
       String _timeDisPlay = '';
       final difference = nowTime.difference(dateTime).inMinutes;
       if (difference < 60){
         _timeDisPlay = '$difference分钟前';
       }else if (difference < 1440){
         _timeDisPlay = "${nowTime.difference(dateTime).inHours}小时";
       }else if (difference < 43200){
         _timeDisPlay = "${nowTime.difference(dateTime).inDays}天前";
       }else{
         _timeDisPlay = createTime;
       }
       print('--$difference--');
       createWidget = Container(
         child: Padding(
           padding:EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
           child: Column(
             mainAxisAlignment: MainAxisAlignment.start,
             crossAxisAlignment: CrossAxisAlignment.stretch,
             children: [
               Container(
                 child: Text(_timeDisPlay??"",style: YBTextStyle.TextStyle7A7A7A12,),
               ),
               Container(
                 height: YBTextStyle.adapterSize10,
               ),
             ],
           ),
         ),
       );
    }else{
       createWidget = Container();
    }


    return Container(
      color: YBColor.white,
      child:InkWell(
        child: Column(
          children: [
            Container(
              child: Padding(
                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize15,bottom: YBTextStyle.adapterSize15),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      child: Text(title??"",style: YBTextStyle.TextStyle30313315Semibold,maxLines: 2,),
                    ),
                    Container(
                      height: 12,
                    ),
                    Container(
                      child: Text(subTitle??"",style: YBTextStyle.textStyle60626614light,maxLines: 2,),
                    ),
                  ],
                ),
              ),
            ),
            createWidget,
            Container(
              child: Padding(
                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                child: Container(
                  height: 1,
                  color: YBColor.homeBorderLineColor,
                ),
              ),
            ),
          ],
        ),
        onTap: (){
          YBApplication.router.navigateTo(context, '/workTaiPage/workTaiGonggaoPage/workTaiGonggaoListDetailPage?ids=$idstr');
        },
      ),
    );
  }
}
